npm install pm2 -g
pm2 start app.js
pm2 start app.js -i N --name SERVICE_NAME
npm restart SERVICE_NAME
pm2 start app.js --max_memory_restart 1024M
pm2 monit
cat /proc/cpuinfo| grep "physical id" | sort| uniq | wc -l
cat /proc/cpuinfo| grep "cpu cores"| uniq
cat /proc/cpuinfo| grep "processor"| wc -l
nginx的主要功能如下
日誌系統對於任意應用而言,通常都是必不可少的一個輔助功能。pm2的相關文件默認存放於$HOME/.pm2/
目錄下,其日誌主要有兩類:
$HOME/.pm2/pm2.log
;$HOME/.pm2/logs/
目錄下,標準誰出日誌存放於${APP_NAME}_out.log
,標準錯誤日誌存放於${APP_NAME}_error.log
;ecosystem.json
下面是開發時ecosystem.json的內容:
採用cluster模式啟動了4個服務進程;如果服務佔用的內存超過300M,會自動進行重啟。
{
apps : [
{
name : "nova",
max_memory_restart: "300M",
script : "/root/nova/app.js",
out_file : "/logs/nova_out.log",
error_file : "/logs/nova_error.log",
instances : 4,
exec_mode : "cluster",
env: {
NODE_ENV: "production"
}
}
]
}
更多相關知識請見官網:ecosystem-file
一個簡單的process.json範例
{
"apps" : [{
"name" : "HTTP-API",
"script" : "http.js"
}],
"deploy" : {
// "production" is the environment name
"production" : {
"user" : "ubuntu",
"host" : ["192.168.0.13"],
"ref" : "origin/master",
"repo" : "git@github.com:Username/repository.git",
"path" : "/var/www/my-repository",
"post-deploy" : "npm install; grunt dist"
},
}
}
/bin/bash:
# Setup deployment at remote location
$ pm2 deploy production setup
# Update remote version
$ pm2 deploy production update
# Revert to -1 deployment
$ pm2 deploy production revert 1
# execute command on remote machines
$ pm2 deploy production exec "pm2 reload all"
更多介紹請見官網:simple-deploy